package com.tj.collection.enums;

import com.fqgj.exception.common.ApplicationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

/**
 * @author moss
 * 2019-04-03
 */
public enum MessageBizCodeEnum {
    /**
     * CASHMAMA
     */
    CASHMAMA_0001("0001", "CashMama注册", MessageSceneEnum.SMS_REGISTER),
    CASHMAMA_0001_BAK("0001", "CashMama登录", MessageSceneEnum.SMS_LOGIN_WITH_OTP),
    CASHMAMA_0002("0002", "CashMama忘记密码", MessageSceneEnum.SMS_FORGET_PASSWORD),
    CASHMAMA_0003("0003", "CashMama更新密码", MessageSceneEnum.SMS_UPLOAD_PASSWORD),
    CASHMAMA_0004("0004", "CashMama绑定新设备", MessageSceneEnum.SMS_BIND_NEW_DEVICE),
    CASHMAMA_0005("0005", "CashMama解冻（多期）", MessageSceneEnum.SMS_ACCOUNT_THAW_REMINDER),
    CASHMAMA_0006("0006", "CashMama解冻（人脸）", MessageSceneEnum.SMS_FACE_THAW_REMINDER),
    CASHMAMA_0007("0007", "CashMama信审通过", MessageSceneEnum.SMS_AUDIT_PASS),
    CASHMAMA_0008("0008", "CashMama信审拒绝（多期）", MessageSceneEnum.SMS_AUDIT_REJECT_MULTIPLE_PERIODS),
    CASHMAMA_0009("0009", "CashMama信审拒绝", MessageSceneEnum.SMS_AUDIT_REJECT),
    CASHMAMA_0010("0010", "CashMama放款完成", MessageSceneEnum.SMS_PAYMENT_NONE),
    CASHMAMA_0012("0012", "CashMama还款前一天提醒", MessageSceneEnum.SMS_REPAYMENT_REMINDER_ADVANCE_1DAY),
    CASHMAMA_0014("0014", "CashMama还款当日提醒", MessageSceneEnum.SMS_REPAYMENT_REMINDER),
    CASHMAMA_0016("0016", "CashMama还款完成", MessageSceneEnum.SMS_REPAYMENT_NONE),
    CASHMAMA_0017("0017", "CashMama代扣（01）", MessageSceneEnum.SMS_WITHHOLD_REMINDER),
    CASHMAMA_0018("0018", "CashMama代扣（02）", MessageSceneEnum.SMS_WITHHOLD_REMINDER_02),
    CASHMAMA_0019("0019", "CashMama代扣（03）", MessageSceneEnum.SMS_WITHHOLD_REMINDER_03),
    CASHMAMA_0020("0020", "CashMama逾期", MessageSceneEnum.SMS_OVERDUE_REMINDER),
    CASHMAMA_0021("0021", "CashMama逾期（多期）", MessageSceneEnum.SMS_OVERDUE_REMINDER_MULTIPLE_PERIODS),
    CASHMAMA_0022("0022", "CashMama后台登录", MessageSceneEnum.SMS_LMS_LOGIN),
    CASHMAMA_0023("0023", "CashMama信息重传", MessageSceneEnum.SMS_REEDIT),
    CASHMAMA_0024("0024", "CashMama借款拒绝（签名失败）", MessageSceneEnum.SMS_LOAN_AUDIT_REJECTION),
    CASHMAMA_0025("0025", "CashMama还款前两天提醒", MessageSceneEnum.SMS_REPAYMENT_REMINDER_ADVANCE_2DAY),
    CASHMAMA_0026("0026", "CashMama提醒再次借款", MessageSceneEnum.SMS_LOAN_AGAIN),
    CASHMAMA_0027("0027", "CashMama签名提醒", MessageSceneEnum.SMS_SIGN_REMIND),
    CASHMAMA_0029("0029", "CASHMAMA签名验证码", MessageSceneEnum.SMS_SIGN_OTP),
    CASHMAMA_0030("0030", "CashMamaHighmark提醒", MessageSceneEnum.SMS_HIGHMARK_REMIND),
    CASHMAMA_0031("0031", "CashMama还款提醒含还款链接", MessageSceneEnum.SMS_REPAYMENT_URL_REMINDER),
    CASHMAMA_0032("0032", "CashMama还款提醒含还款链接(已承诺还款)", MessageSceneEnum.SMS_REPAYMENT_URL_REMINDER2),
    CASHMAMA_0033("0033", "CashMama触发抵扣通知用户", MessageSceneEnum.SMS_DEDUCT_REMINDER),
    CASHMAMA_0034("0034", "CashMama罚息抵扣提醒短信", MessageSceneEnum.OVERDUE_FEE_DISCOUNT_REMIND_SMS),
    CASHMAMA_0035("0035", "CashMama提醒用户提现短信", MessageSceneEnum.SMS_PENDING_WITHDRAWAL),
    CASHMAMA_0036("0036", "CashMama打款失败提醒用户", MessageSceneEnum.SMS_PAYMENT_FAILURE),
    CASHMAMA_1001("1001", "CashMama通知下载Loanzone", MessageSceneEnum.DOWNLOAD_NEW_APP_REMIND),
    CASHMAMA_EMAIL("EMAIL_COMMON_CONTENT", "通用邮件", MessageSceneEnum.COMMON_EMAIL),
    CASHMAMA_CUSTOMER_EMAIL("CUSTOMER_EMAIL", "客服邮件", MessageSceneEnum.CUSTOMER_EMAIL),
    ;

    private static final Logger logger = LoggerFactory.getLogger(MessageBizCodeEnum.class);

    private String bizCode;
    private String desc;
    private MessageSceneEnum messageSceneEnum;

    /**
     * @param bizCode          消息中心的 BizCode
     * @param desc             描述
     * @param messageSceneEnum 消息场景码
     */
    MessageBizCodeEnum(String bizCode, String desc, MessageSceneEnum messageSceneEnum) {
        this.bizCode = bizCode;
        this.desc = desc;
        this.messageSceneEnum = messageSceneEnum;
    }

    /**
     * 获取场景码  appName大写+编号 例：CASHMAMA_0001
     *
     * @param appName
     * @param messageSceneEnum
     * @return
     */
    public static String getMessageBizCodeEnum(String appName, MessageSceneEnum messageSceneEnum) {
        Assert.notNull(appName, "appName is null");
        Assert.notNull(messageSceneEnum, "messageSceneEnum is null");
        MessageBizCodeEnum[] values = MessageBizCodeEnum.values();
        for (MessageBizCodeEnum value : values) {
            if (value.messageSceneEnum.equals(messageSceneEnum)) {
                return appName.toUpperCase() + "_" + value.getBizCode();
            }
        }
        logger.error("获取场景码失败,appName:{},messageSceneEnum:{}", appName, messageSceneEnum);
        throw new ApplicationException("unknown error!");
    }

    /**
     * 获取场景码  appName大写+编号 例：CASHMAMA_0001
     *
     * @param packageName
     * @param messageSceneEnum
     * @return
     */
    public static String getMessageBizCodeByPackageName(String packageName, MessageSceneEnum messageSceneEnum) {
        Assert.notNull(packageName, "packageName is null");
        Assert.notNull(messageSceneEnum, "messageSceneEnum is null");
        MessageBizCodeEnum[] values = MessageBizCodeEnum.values();
        for (MessageBizCodeEnum value : values) {
            if (value.messageSceneEnum.equals(messageSceneEnum)) {
                return packageName.replaceAll("\\.", "").toUpperCase() + "_" + value.getBizCode();
            }
        }
        logger.error("获取场景码失败,packageName:{},messageSceneEnum:{}", packageName, messageSceneEnum);
        throw new ApplicationException("unknown error!");
    }

    public String getBizCode() {
        return bizCode;
    }

    public MessageBizCodeEnum setBizCode(String bizCode) {
        this.bizCode = bizCode;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    public MessageBizCodeEnum setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    public MessageSceneEnum getMessageSceneEnum() {
        return messageSceneEnum;
    }

    public MessageBizCodeEnum setMessageSceneEnum(MessageSceneEnum messageSceneEnum) {
        this.messageSceneEnum = messageSceneEnum;
        return this;
    }
}
